export const useRandomMember = () => {
  return (count: number, members: string[], excludes: string[] = []) => {
    const winners: string[] = [];
    const getRandomMember = () => {
      console.log(winners, count);
      // 取够了就不循环了
      if (winners.length >= count) return;
      // 随机取一个
      const winner = members.filter((member) => !excludes.includes(member))[
        Number(Math.floor(Math.random() * members.length))
      ];
      if (!winner) {
        getRandomMember();
        return;
      }
      // 如果重复了，重新取,不插入，否则插入数组中
      if (!winners.includes(winner)) {
        winners.push(winner);
      }
      getRandomMember();
    };
    // 开始生成
    getRandomMember();
    return winners;
  };
};
